using UnityEngine;

namespace NodeCanvas.BehaviourTrees
{
	[AddComponentMenu("")]
	[Category("Mutators (beta)")]
	[Name("Root Switcher")]
	[Description("Switch the root node of the behaviour tree to a new one defined by tag\nBeta Feature!")]
	public class BTRootSwitcher : BTNodeBase
	{
		public string targetNodeTag;

		private Node targetNode;

		protected override Status OnExecute(Component agent, Blackboard blackboard)
		{
			targetNode = base.graph.GetNodeWithTag<Node>(targetNodeTag);
			if (targetNode != null)
			{
				if (base.graph.primeNode != targetNode)
				{
					base.graph.primeNode = targetNode;
				}
				return Status.Success;
			}
			return Status.Failure;
		}
	}
}
